package GUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ContainerListener;

public class A2 extends JFrame {
    JLabel label;
    public A2(String title){
        super(title);
         label = new JLabel("hello worlds");
        Container container =getContentPane();
        container.add(label,BorderLayout.NORTH);
        JButton button = new JButton("按钮1");
        container.add(button,BorderLayout.CENTER);
        JButton button1 = new JButton("按钮二");
        container.add(button1,BorderLayout.SOUTH);
        setSize(300,120);
        setVisible(true);
        button.addActionListener( new A());
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                label.setText("标签2");
            }
        });




    }
    class A implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e){
            label.setText("标签1");
        }
    }
}
